function showToast(options) {
  const pages = getCurrentPages()
  const currentPage = pages[pages.length - 1]
  const toast = currentPage.selectComponent('#customToast')
  
  if (!toast) {
    console.warn('未找到 custom-toast 组件')
    return wx.showToast(options)
  }
  
  const { title, duration = 1500, mask = false } = options
  
  toast.setData({
    text: title,
    duration,
    mask
  })
  
  toast.show()
  
  if (duration > 0) {
    return setTimeout(() => {
      toast.hide()
    }, duration)
  }
  
  return {
    hide: () => toast.hide()
  }
}

function hideToast() {
  const pages = getCurrentPages()
  const currentPage = pages[pages.length - 1]
  const toast = currentPage.selectComponent('#customToast')
  
  if (toast) {
    toast.hide()
  } else {
    wx.hideToast()
  }
}

module.exports = {
  showToast,
  hideToast
}